
# -*- coding: utf-8 -*-

from config.Config import USER_LOGIN_LIST
from controllers.BaseController import BaseController

class LoginController(BaseController):
	def get(self):
		self.render("facedetect.html", userid=self.get_secure_cookie('userid'))

	def post(self):
		try:
			username = self.get_argument("username", None)
			password = self.get_argument("password", None)
			nextpage = self.get_argument("next", None)
			if nextpage == "" or nextpage is None:
				nextpage = "/"

			if username and password:
				for user in USER_LOGIN_LIST:
					if username == user["username"] and password == user["password"]:
						self.set_secure_cookie("userid", str(user["id"]), expires_days=7)
						self.redirect(nextpage)
						return
		except:
			pass
		self.clear_cookie('userid')
		self.redirect("/")
